package dispatcher.person.gui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import state.Globals;
import state.person.Person;

import dispatcher.gui.event.PersonCreatedThread;
import dispatcher.person.gui.PersonDispatcherView;

/**
 * This class handles actions done by the create button on the 
 * PersonDispatcherView
 * @author Caleb
 *
 */
public class CreatePersonCreatorActionListener implements ActionListener {
	private PersonDispatcherView view;
	
	public CreatePersonCreatorActionListener(PersonDispatcherView view){
		this.view = view;
	}
	@Override
	public void actionPerformed(ActionEvent arg0) {
		
		// Creates a person from the GUI state
		Person p = view.createPerson();
		
		// Passes the created person to the network handler to be
		// set to the PersonDispatcher
		
		if (p != null){
			Globals.getLogger().log("Name : " + p.getName());
			Globals.getLogger().log("Type : " + p.getType());
			Globals.getLogger().log("Weight : " + p.getWeight());
			Globals.getLogger().log("Call Source : " + p.getHallCall().getFloor());
			Globals.getLogger().log("Call Direction : " + p.getHallCall().getDirection());
			Globals.getLogger().log("Dest : " + p.getDestination());
			Globals.getLogger().log("State : " + p.getState());
			Globals.getLogger().log("HashCode : " + p.hashCode());
			
			(new PersonCreatedThread(view.createPerson(), view.getNetworkHandler())).start();
			// Reset all the fields when done
			view.resetFields();
		}else{
			Globals.getLogger().log("Create Person Failed", this.getClass().getName(), "actionPerformed");
		}
	}

}
